home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: New Zealand Amiga Users Group
/
New Zealand Amiga Users Group Newsdisk v07 (1987-08)(NZAmigaUG).zip
/
New Zealand Amiga Users Group Newsdisk v07 (1987-08)(NZAmigaUG).adf
/
ANSI Fix.BAS
< prev
next >
Wrap
BASIC Source File
|
1993-12-02
|
2KB
|
60 lines
REM Program to fix 'printer ready' files containing ANSI attribute sequences
REM so that the CONSOLE device driver handles them properly.
REM The problem is that the CONSOLE device driver doesn't recognise the
REM underline, bold, and italic OFF sequences. So I substitute the Plain
REM text attribute. This simple approach works except when you turn on
REM more than one attribute, then turn off only one. eg a paragraph
REM displayed in italics with an underlined bit in the middle results in
REM the the italics being turned off at the end of the underlined bit.
REM To do a proper job you need to design a complete state machine to keep
REM track the attributes - then again you might as well write a new CONSOLE
REM device handler.
LINE INPUT "Filename : ";fil$
PRINT "Output file will be called ";fil$+".fixed"
OPEN fil$ FOR INPUT AS #1
OPEN fil$+".fixed" FOR OUTPUT AS #2
WHILE NOT EOF(1)
b$=""
l=0
LINE INPUT # 1,l$
FOR i=1 TO LEN(l$)
a$=MID$(l$,i,1)
IF a$ = CHR$(27) THEN
l=1
PRINT #2,a$;
ELSE
IF l=1 AND a$="[" THEN
l=2
PRINT #2,a$;
ELSE
IF (l=2 OR l=3) THEN
IF a$>="0" AND a$<="9" THEN
b$=b$+a$
l=l+1
ELSE
PRINT #2,b$;a$;
b$=""
l=0
END IF
ELSE
IF l=4 THEN
IF a$="m" AND (b$="22" OR b$="23" OR b$="24") THEN b$="0"
b$=b$+a$
PRINT #2,b$;
b$=""
l=0
ELSE
PRINT #2,a$;
END IF
END IF
END IF
END IF
NEXT i
PRINT #2,CHR$(10);
WEND
CLOSE
PRINT "All fixed"
END